package com.allqj;


import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @description: 时间处理Util
 * @author: cmy
 * @date: 2018/9/10 10:43
 **/
public class DateTimeUtil {


   /* private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private static DateFormat dateFormat1 = new SimpleDateFormat("yyyy-M-d");
    private static DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");*/


    private static ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd");
        }
    };

    private static ThreadLocal<DateFormat> dateFormat1 = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-M-d");
        }
    };

    private static ThreadLocal<DateFormat> dateTimeFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
    };

    private static ThreadLocal<DateFormat> dayStartFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        }
    };

    private static ThreadLocal<DateFormat> timeFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("HH:mm:ss");
        }
    };

    private static ThreadLocal<DateFormat> dateMonthFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM");
        }
    };


    public static String timeFormat(Date date) {
        return timeFormat.get().format(date);
    }

    public static String timeFormat(Long date) {
        return timeFormat.get().format(date);
    }

    /**
     * @param date
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 格式化时间
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */
    public static String dateTimeFormat(Date date) {
        return dateTimeFormat.get().format(date);
    }

    public static String dateMonthFormat(Date date) {
        return dateMonthFormat.get().format(date);
    }

    public static String dateFormat(Date date) {
        return dateFormat.get().format(date);
    }

    /**
     * 格式化日期 例 2018-5-1
     *
     * @param date
     * @return
     */
    public static String dateFormat1(Date date) {
        return dateFormat1.get().format(date);
    }

    public static String dateFormat(Long date) {
        return dateFormat.get().format(date);
    }

    public static Date strToDate(String dateTime) {
        Date date = null;
        try {
            date = dateFormat.get().parse(dateTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date strToDateTime(String dateTime) {
        Date date = null;
        try {
            date = dateTimeFormat.get().parse(dateTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * @param date
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 格式化时间一天的第一秒
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */
    public static String dayStartFormat(Date date) {
//        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        return dayStartFormat.get().format(date);
    }

    /**
     * @param date
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 格式化时间一天的最后一秒
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */
    public static String dayEndFormat(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
        return dateFormat.format(date);
    }

    /**
     * @param date
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 格式化时间一天的第一秒
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */
    public static Date dayStartTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();

    }

    /**
     * @param date
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 格式化时间一天的最后一秒
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */
    public static Date dayEndTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * @param
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 一天的毫秒数
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */
    public static Long getOneDayMillisecond() {
        return 1000 * 60 * 60 * 24L;
    }

    /**
     * @param
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 半天的毫秒数
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */
    public static Long getHalfOneDayMillisecond() {
        return 1000 * 60 * 60 * 12L;
    }


    /**
     * 格式日期 yyyyMMdd
     *
     * @param date
     * @return
     */
    public static String dateNumFormat(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        return dateFormat.format(date);
    }

    /**
     * @param dateTime
     * @Author: cmy
     * @Date: 2018/10/11
     * @Description: 判断一个时间戳是上午还是下午
     * @UpdateDate: 2018/10/11
     * @UpdateDescription:
     */

    /**
     * @param date
     * @Author: cmy
     * @Date: 2018/10/20
     * @Description: 获取时间月份的第一天0点0时0分
     * @UpdateDate: 2018/10/20
     * @UpdateDescription:
     */
    public static Date firstDayForMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
//        return dateTimeFormat(calendar.getTime());
        return calendar.getTime();
    }
    /*public static Date firstDayForMonth(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND,0);
        return calendar.getTime();
    }*/

    /**
     * @param date
     * @Author: cmy
     * @Date: 2018/10/20
     * @Description: 获取当月最后一天
     * @UpdateDate: 2018/10/20
     * @UpdateDescription:
     */
    public static Date lastDayForMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
//        return dateTimeFormat(calendar.getTime());
        return calendar.getTime();
    }

//    public static Date stringToDate(String dateTimeStr) {
//        Date datetime = null;
//        try {
//            datetime = dateTimeFormat.get().parse(dateTimeStr);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return datetime;
//    }
//
//    public static Long stringToLong(String dateTimeStr) {
//        Date datetime = null;
//        try {
//            datetime = dateTimeFormat.get().parse(dateTimeStr);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return datetime.getTime();
//    }


    /**
     * @param date 日期
     * @Author: liuxin
     * @Date: 18/10/18
     * @Description: 获取整月的第一天含上个月的日期
     * @UpdateDate: 18/10/18
     * @UpdateDescription: 判断当月一号所在周的周一是几号
     */
    public static Date getFirstDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        //指定日期为1号
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        if (calendar.get(Calendar.DAY_OF_WEEK) == 1)
            calendar.add(Calendar.DAY_OF_MONTH, -1);
        calendar.setTime(calendar.getTime());
        calendar.add(Calendar.DATE, calendar.getFirstDayOfWeek() - calendar.get(Calendar.DAY_OF_WEEK) + 1);
        return calendar.getTime();
    }

    /**
     * @param date 日期
     * @Author: liuxin
     * @Date: 18/10/18
     * @Description: 判断当月最后一天所在周的周末是几号 含下个月的日期
     * @UpdateDate: 18/10/18
     * @UpdateDescription:
     */
    public static Date getLastDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        // 如果是周日直接返回
        if (calendar.get(Calendar.DAY_OF_WEEK) != 1) {
            calendar.add(Calendar.DATE, 14 - calendar.get(Calendar.DAY_OF_WEEK) + 1);
        }
        return calendar.getTime();
    }

    /**
     * @param date
     * @Author: liuxin
     * @Date: 19/10/18
     * @Description: 格式化 2018年10月1日～31日
     * @UpdateDate: 19/10/18
     * @UpdateDescription:
     */
    public static String getStartAndLastDay(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        String firstDay = dateFormat.format(cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        String lastDay = dateFormat.format(cal.getTime());
        String monthDay = firstDay + "~" + lastDay.substring(lastDay.length() - 3, lastDay.length());
        return monthDay;
    }


    /**
     * @param start
     * @param end
     * @Author: liuxin
     * @Date: 2018/12/5
     * @Description: 格式化时间
     * @UpdateDate: 29/10/18
     * @UpdateDescription:
     */
    public static String getStartAndLastDay(Date start, Date end) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar cal = Calendar.getInstance();
        cal.setTime(start);
//        cal.set(Calendar.DAY_OF_MONTH, 1);
        String firstDay = dateFormat.format(cal.getTime());
        cal.setTime(end);
        String lastDay = dateFormat.format(cal.getTime());
        String monthDay = firstDay + "~" + lastDay.substring(lastDay.length() - 3, lastDay.length());
        return monthDay;
    }

    /**
     * @param start
     * @param end
     * @Author: liuxin
     * @Date: 2018/12/5
     * @Description: 格式化时间
     * @UpdateDate: 29/10/18
     * @UpdateDescription:
     */
    public static String getStartAndLastDayNumber(Date start, Date end) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(start);
//        cal.set(Calendar.DAY_OF_MONTH, 1);
        String firstDay = dateFormat.format(cal.getTime());
        cal.setTime(end);
        String lastDay = dateFormat.format(cal.getTime());
        String monthDay = firstDay + "-" + lastDay;
        return monthDay;
    }

    /**
     * @param fromDate
     * @param toDate
     * @Author: liuxin
     * @Date: 19/10/18
     * @Description: 获取时间段所有月份
     * @UpdateDate: 19/10/18
     * @UpdateDescription:
     */
    public static List<Date> getMonthList(Date fromDate, Date toDate) {
        List<Date> daysList = new ArrayList<>();
        Date startDate = fromDate;
        Date endDate = toDate;
        if (compareTwoDate(fromDate, toDate) > 0) {
            startDate = toDate;
            endDate = fromDate;
        }
        Date startMonthDay;
        Date endMonthDay;
//        try {
        startMonthDay = getFirstDayOfMonth(startDate);
        endMonthDay = getFirstDayOfMonth(endDate);
//        } catch (ParseException e) {
//            e.printStackTrace();
//            throw new ServiceException("日期格式转换失败");
//        }
        daysList.add(startMonthDay);
        // 获取下个月开始日期
        Date nextMonthDay = getCountedMonth(startMonthDay, "1");
        while (compareTwoDate(nextMonthDay, endMonthDay) <= 0) {
            daysList.add(nextMonthDay);
            nextMonthDay = getCountedMonth(nextMonthDay, "1");
        }
        return daysList;
    }

    /**
     * 获取时间段所有月份
     *
     * @param fromDate 开始时间
     * @param toDate   结束时间
     * @return
     */
   /* public static List<String> getMonthList(Date fromDate, Date toDate) {
        ArrayList<String> result = new ArrayList<>();
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(fromDate);
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
        max.setTime(toDate);
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
        Calendar curr = min;
        while (curr.before(max)) {
            result.add(dateTimeFormat(curr.getTime()));
            curr.add(Calendar.MONTH, 1);
        }
        return result;
    }*/

    /**
     * @param fromDate
     * @param toDate
     * @Author: liuxin
     * @Date: 19/10/18
     * @Description: 比较两个日期
     * @UpdateDate: 19/10/18
     * @UpdateDescription:
     */
    public static int compareTwoDate(Date fromDate, Date toDate) {
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

//            Date fDate = sdf.parse(fromDate);
//            Date tDate = sdf.parse(toDate);
        if (fromDate.getTime() > toDate.getTime()) {
            return 1;
        } else if (fromDate.getTime() < toDate.getTime()) {
            return -1;
        } else {
            return 0;
        }

    }

    /**
     * @param strDate
     * @Author: liuxin
     * @Date: 19/10/18
     * @Description: 获取给定日期字符串的月------ 一号日期
     * @UpdateDate: 19/10/18
     * @UpdateDescription:
     */
    public static Date getFirstDayOfMonth(Date strDate) {
        Calendar c = Calendar.getInstance();
        c.setTime(strDate);
        final int last = c.getActualMinimum(Calendar.DAY_OF_MONTH);
        c.set(Calendar.DAY_OF_MONTH, last);
        return c.getTime();
    }

    /**
     * @param strDate
     * @Author: liuxin
     * @Date: 19/10/18
     * @Description: 获取给定日期字符串的月的最后一号的日期
     * @UpdateDate: 19/10/18
     * @UpdateDescription:
     */
    public static Date getLastDayOfMonth(Date strDate) {
        Calendar c = Calendar.getInstance();
        c.setTime(strDate);
        final int last = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        c.set(Calendar.DAY_OF_MONTH, last);
        return c.getTime();
    }

    /**
     * @param strDate
     * @param delay
     * @Author: liuxin
     * @Date: 19/10/18
     * @Description: 得到一个时间延后或前移几月的时间
     * @UpdateDate: 19/10/18
     * @UpdateDescription:
     */
    public static Date getCountedMonth(Date strDate, String delay) {
        Calendar currentDate = Calendar.getInstance();
        currentDate.setTime(strDate);
        currentDate.add(Calendar.MONTH, Integer.parseInt(delay));
        return currentDate.getTime();
    }

    /**
     * @param time
     * @Author: liuxin
     * @Date: 01/11/18
     * @Description: 时间戳转换string
     * @UpdateDate: 01/11/18
     * @UpdateDescription:
     */
    public static String getDoubleToString(double time) {
        return dateFormat.get().format(time);
    }

    /**
     * @param date
     * @Author: liuxin
     * @Date: 01/11/18
     * @Description: 前一天日期
     * @UpdateDate: 01/11/18
     * @UpdateDescription:
     */
    public static Date getBeforDay(Date date) {
        /*DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date dates = dateFormat.parse(date);*/
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        return calendar.getTime();
    }

    /**
     * @param date
     * @Author: liuxin
     * @Date: 01/11/18
     * @Description: 后一天日期
     * @UpdateDate: 01/11/18
     * @UpdateDescription:
     */
    public static Date getNextDay(String date) throws ParseException {
        Date dates = dateFormat.get().parse(date);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dates);
        calendar.add(Calendar.DAY_OF_MONTH, +1);
        Date day = calendar.getTime();
        return day;
    }

    /**
     * @param strDate
     * @param delay
     * @Author: liuxin
     * @Date: 19/10/18
     * @Description: 得到一个时间延后或前移几天的时间
     * @UpdateDate: 19/10/18
     * @UpdateDescription:
     */
    public static Date getCountedDay(Date strDate, Integer delay) {
        Calendar currentDate = Calendar.getInstance();
        currentDate.setTime(strDate);
        currentDate.add(Calendar.DATE, delay);
        return currentDate.getTime();
    }

    /**
     * @param time
     * @Author: liuxin
     * @Date: 20/11/18
     * @Description: 年
     * @UpdateDate: 20/11/18
     * @UpdateDescription:
     */
    public static Integer getYear(Date time) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy");
        return Integer.valueOf(dateFormat.format(time));
    }

    /**
     * @param time
     * @Author: liuxin
     * @Date: 20/11/18
     * @Description: 月
     * @UpdateDate: 20/11/18
     * @UpdateDescription:
     */
    public static Integer getMonth(Date time) {
        DateFormat dateFormat = new SimpleDateFormat("MM");
        return Integer.valueOf(dateFormat.format(time));
    }

    /**
     * @param time
     * @Author: liuxin
     * @Date: 21/11/18
     * @Description: 日
     * @UpdateDate: 21/11/18
     * @UpdateDescription:
     */
    public static Integer getDay(Date time) {
        DateFormat dateFormat = new SimpleDateFormat("dd");
        return Integer.valueOf(dateFormat.format(time));
    }

    /**
     * @param time
     * @Author: liuxin
     * @Date: 20/11/18
     * @Description: 整个日历的最后一天
     * @UpdateDate: 20/11/18
     * @UpdateDescription:
     */
    public static Integer getMaxDay(Date time) {
        DateFormat dateFormat = new SimpleDateFormat("dd");
        return Integer.valueOf(dateFormat.format(DateTimeUtil.lastDayForMonth(time)));
    }


    /**
     * @param time
     * @Author: liuxin
     * @Date: 20/11/18
     * @Description: 整个日历的开始第一天
     * @UpdateDate: 20/11/18
     * @UpdateDescription:
     */
    public static Integer getMinDay(Date time) {
        DateFormat dateFormat = new SimpleDateFormat("dd");
        return Integer.valueOf(dateFormat.format(DateTimeUtil.firstDayForMonth(time)));
    }


    public static long getDays(Date start, Date end) {
        long aa = start.getTime();
        long bb = end.getTime();
        return (bb - aa) / (1000 * 3600 * 24);
    }


    /**
     * @param startTime
     * @Author: liuxin
     * @Date: 2018/12/2
     * @Description: 星期一  星期二  星期三 星期四 星期五 星期六 星期日
     * @UpdateDate: 29/10/18
     * @UpdateDescription:
     */
    public static List<Integer> getWeekList(Date startTime, Date endTime) {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        Calendar d = Calendar.getInstance();
        d.setTime(startTime);
        String weekdays[] = new DateFormatSymbols().getShortWeekdays(); //保存7个星期名
        List<Integer> weekList = new ArrayList<>();
        while (true) {
//            SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
//            String week = sdf.format(d.getTime());
//            weekList.add(week);
            int aa = d.get(Calendar.DAY_OF_WEEK);
            weekList.add(aa);
            d.add(Calendar.DAY_OF_MONTH, 1);
            if (d.getTime().after(endTime)) break;
        }
        return weekList;
    }


    /**
     * @param startTime
     * @param endTime
     * @Author: yc
     * @Date: 2020-01-16 17:22
     * @Description: 获取请假在整月的一个星期多少天
     */
    public static Map<Integer, Double> getRestWeekCountInfo(Date startTime, Date endTime) {
        Map<Integer, Double> info = new HashMap<>();

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startTime);
        calendar.set(Calendar.DATE, 1); // 获取当月的第一天

        int month = calendar.get(Calendar.MONTH);
        int count = 0;
        while (calendar.get(Calendar.MONTH) == month) {
            double days = 0;
            // 判断当前时间是不是周一
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
                // 周一的时间
                Date monday = dayStartTime(calendar.getTime());
                // 周日的时间
                calendar.add(Calendar.DATE, 6);
                Date sunday = dayEndTime(calendar.getTime());

                days = getRestWeekDays(monday, sunday, startTime, endTime);
            } else {
                // 获取星期几
                int weekNum = calendar.get(Calendar.DAY_OF_WEEK);
                // 如果当前星期为星期日
                if (weekNum == Calendar.SUNDAY) {
                    // 周一的时间
                    Date monday = dayStartTime(calendar.getTime());
                    Date sunday = dayEndTime(calendar.getTime());

                    days = getRestWeekDays(monday, sunday, startTime, endTime);
                } else {
                    Date monday = dayStartTime(calendar.getTime());
                    calendar.add(Calendar.DATE, (Calendar.SATURDAY - weekNum) + 1);
                    Date sunday = dayEndTime(calendar.getTime());
                    days = getRestWeekDays(monday, sunday, startTime, endTime);
                }
            }
            info.put(++count, days);

            calendar.add(Calendar.DATE, 1);
        }

        return info;
    }


    private static double getRestWeekDays(Date monday, Date sunday, Date startTime, Date endTime) {
        double days = 0;
        // 请假开始的时间在这一周中
        if (monday.getTime() <= startTime.getTime() && startTime.getTime() <= sunday.getTime()
                && monday.getTime() <= endTime.getTime() && endTime.getTime() <= sunday.getTime()) {
            days = getDingDingDays(startTime, endTime);
        } else if (monday.getTime() <= startTime.getTime() && startTime.getTime() <= sunday.getTime()
                && sunday.getTime() < endTime.getTime()) {
            days = getDingDingDays(startTime, sunday);
        } else if (startTime.getTime() < monday.getTime()
                && monday.getTime() <= endTime.getTime() && endTime.getTime() <= sunday.getTime()) {
            days = getDingDingDays(monday, endTime);
        } else if (startTime.getTime() < monday.getTime()
                && sunday.getTime() < endTime.getTime()) {
            days = getDingDingDays(monday, sunday);
        }
        return days;
    }

    /**
     * @param startTime
     * @param endTime
     * @Author: liuxin
     * @Date: 2018/12/2
     * @Description: 日期   1~31
     * @UpdateDate: 29/10/18
     * @UpdateDescription:
     */
    public static List<Integer> getDayList(Date startTime, Date endTime) {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        Calendar d = Calendar.getInstance();
        d.setTime(startTime);
//        int month = d.get(Calendar.MONTH); //用于循环打印当前月份的月历__月份判断
        List<Integer> dayList = new ArrayList<>();

        /*************************************************
         * 不跨月日期判断
         * */
        /*d.set(Calendar.DAY_OF_MONTH, 1); //设置d的日期为当月1号
        do {
            int day = d.get(Calendar.DAY_OF_MONTH);
            dayList.add(day);
            d.add(Calendar.DAY_OF_MONTH, 1);
        } while (d.get(Calendar.MONTH) == month);*/

        while (true) {
            int day = d.get(Calendar.DAY_OF_MONTH);
            dayList.add(day);
            d.add(Calendar.DAY_OF_MONTH, 1);
            if (d.getTime().after(endTime)) break;
        }

        return dayList;
    }


    /**
     * @param date
     * @Author: liuxin
     * @Date: 2018/12/2
     * @Description: 日期   1~31
     * @UpdateDate: 29/10/18
     * @UpdateDescription:
     */
    public static Integer getDays(Date date) {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        Calendar d = Calendar.getInstance();
        d.setTime(date);
        int day = d.get(Calendar.DAY_OF_MONTH);
        return day;
    }

    /**
     * @param startTime
     * @param endTime
     * @Author: yc
     * @Date: 2020-01-16 15:43
     * @Description: 获取两个时间段的天数
     */
    public static int getDistanceDays(Date startTime, Date endTime) {
        long one = startTime.getTime();
        long two = endTime.getTime();
        long diff;
        if (one < two) {
            diff = two - one;
        } else {
            diff = one - two;
        }
        long days = diff / getOneDayMillisecond();
        return (int) days;
    }

    /**
     * @param startTime
     * @param endTime
     * @Author: yc
     * @Date: 2020-01-16 17:55
     * @Description: 获取钉钉时间段之间的天数
     */
    public static double getDingDingDays(Date startTime, Date endTime) {
        long one = startTime.getTime();
        long two = endTime.getTime();

        if (timeFormat(endTime).equals("23:59:59"))
            two = two + 1000;
        else if (timeFormat(endTime).equals("11:59:59"))
            two = two + 1000;

        long diff;
        if (one < two) {
            diff = two - one;
        } else {
            diff = one - two;
        }

        return (double) diff / getOneDayMillisecond();
    }



    /**
     * @param startTime
     * @Author: yc
     * @Date: 2020-03-05 14:18
     * @Description: 验证是否是整月的月份
     */
    public static boolean verifyMonth(Date startTime, Date endTime) {

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        // 查询月份的第一天 不带时间处理
        String firstDay = df.format(DateTimeUtil.getFirstDayOfMonth(startTime));
        // 查询月份的最后一天 不带时间处理
        String lastDay = df.format(DateTimeUtil.getLastDayOfMonth(startTime));

        // 判断是否是整月范围查询 不是整月的查询跳出 不做处理
        if (!firstDay.equals(df.format(startTime)) || !lastDay.equals(df.format(endTime))) {
            return false;
        }

        // 当月的第一天 0点开始
        Date currenyFirstTime = DateTimeUtil.firstDayForMonth(new Date());
        // 判断现在是时间是否大于查询的结束时间 当前的时间大于的时候返回true
        return currenyFirstTime.compareTo(endTime) > 0;
    }

}